package leet.ku._14;

public class Solution {
	public String longestCommonPrefix(String[] strs) {
		if (strs.length <= 0)
			return "";
		String result = strs[0];
		for (int i = 1; i < strs.length && result != null && result.length() > 0; i++) {
			if (strs[i] == null)
				result = "";
			else {
				int j = 0;
				while (j < result.length() && j < strs[i].length() && result.charAt(j) == strs[i].charAt(j))
					j++;
				if (j <= 0)
				    result = "";
				else
					result = result.substring(0, j);
			}
		}
		if (result == null)
			return "";
		return result;
	}
}
